'use strict';

const BaseController = require('../../core/base_controller');

class AdsController extends BaseController {
    async index() {
        const { ctx } = this;
        const { page = 1, pageSize = 10 } = ctx.query;
        let data = await ctx.service.cache.get('ads_list', 'arr');

        const start = (page - 1) * pageSize;
        const end = start + parseInt(pageSize);
        const list = data.slice(start, end);

        this.success({
            list,
            pagination: {
                total: data.length,
                current: parseInt(page),
                pageSize: parseInt(pageSize)
            }
        });
    }
}

module.exports = AdsController;
